/*  1:   */ package org.intellij.plugins.relaxNG.compact.psi.impl;
/*  2:   */ 
/*  3:   */

import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.ResolveState;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.xml.util.XmlUtil;
import org.intellij.plugins.relaxNG.compact.RncFileType;
import org.intellij.plugins.relaxNG.compact.RncTokenTypes;
import org.intellij.plugins.relaxNG.compact.psi.RncFile;
import org.intellij.plugins.relaxNG.compact.psi.RncFileReference;
import org.intellij.plugins.relaxNG.compact.psi.util.EscapeUtil;
import org.intellij.plugins.relaxNG.references.FileReferenceUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */
/* 16:   */
/* 17:   */
/* 18:   */
/* 19:   */
/* 20:   */ 
/* 21:   */ abstract class RncFileReferenceImpl
/* 22:   */   extends RncElementImpl
/* 23:   */   implements RncFileReference
/* 24:   */ {
/* 25:   */   public RncFileReferenceImpl(ASTNode paramASTNode)
/* 26:   */   {
/* 27:44 */     super(paramASTNode);
/* 28:   */   }
/* 29:   */   
/* 30:   */   @NotNull
/* 31:   */   public PsiReference[] getReferences()
/* 32:   */   {
/* 33:51 */     ASTNode localASTNode = getNode().findChildByType(RncTokenTypes.LITERAL);
/* 34:52 */     if (localASTNode == null)
/* 35:   */     {
/* 36:52 */       PsiReference[] tmp20_17 = PsiReference.EMPTY_ARRAY;
/* 37:52 */       if (tmp20_17 == null) {
/* 38:52 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncFileReferenceImpl", "getReferences" }));
/* 39:   */       }
/* 40:52 */       return tmp20_17;
/* 41:   */     }
/* 42:54 */     String str = localASTNode.getText();
/* 43:55 */     FileReferenceSet localFileReferenceSet = new FileReferenceSet(str.substring(1, str.length() - 1), this, getReferenceRange().getStartOffset(), null, true, false); PsiReference[] 
/* 44:   */     
/* 45:   */ 
/* 46:   */ 
/* 47:   */ 
/* 48:60 */       tmp102_99 = FileReferenceUtil.restrict(localFileReferenceSet, FileReferenceUtil.byType(RncFileType.getInstance()));
/* 49:60 */     if (tmp102_99 == null) {
/* 50:60 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncFileReferenceImpl", "getReferences" }));
/* 51:   */     }
/* 52:60 */     return tmp102_99;
/* 53:   */   }
/* 54:   */   
/* 55:   */   public RncFile getReferencedFile()
/* 56:   */   {
/* 57:64 */     String str = getFileReference();
/* 58:65 */     if (str != null)
/* 59:   */     {
/* 60:66 */       PsiFile localPsiFile = XmlUtil.findRelativeFile(str, getContainingFile());
/* 61:67 */       if ((localPsiFile instanceof RncFile)) {
/* 62:68 */         return (RncFile)localPsiFile;
/* 63:   */       }
/* 64:   */     }
/* 65:71 */     return null;
/* 66:   */   }
/* 67:   */   
/* 68:   */   @Nullable
/* 69:   */   public String getFileReference()
/* 70:   */   {
/* 71:76 */     ASTNode localASTNode = getNode().findChildByType(RncTokenTypes.LITERAL);
/* 72:77 */     if (localASTNode == null) {
/* 73:77 */       return null;
/* 74:   */     }
/* 75:78 */     String str = EscapeUtil.unescapeText(localASTNode);
/* 76:79 */     return str.substring(1, str.length() - 1);
/* 77:   */   }
/* 78:   */   
/* 79:   */   public TextRange getReferenceRange()
/* 80:   */   {
/* 81:83 */     ASTNode localASTNode = getNode().findChildByType(RncTokenTypes.LITERAL);
/* 82:84 */     if (localASTNode == null) {
/* 83:84 */       return TextRange.from(0, 0);
/* 84:   */     }
/* 85:85 */     int i = localASTNode.getStartOffset() - getTextOffset() + 1;
/* 86:86 */     return TextRange.from(i, localASTNode.getTextLength() - 2);
/* 87:   */   }
/* 88:   */   
/* 89:   */   public boolean processDeclarations(@NotNull PsiScopeProcessor paramPsiScopeProcessor, @NotNull ResolveState paramResolveState, PsiElement paramPsiElement1, @NotNull PsiElement paramPsiElement2)
/* 90:   */   {
/* 91:91 */     if (paramPsiScopeProcessor == null) {
/* 92:91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/compact/psi/impl/RncFileReferenceImpl", "processDeclarations" }));
/* 93:   */     }
/* 94:91 */     if (paramResolveState == null) {
/* 95:91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/intellij/plugins/relaxNG/compact/psi/impl/RncFileReferenceImpl", "processDeclarations" }));
/* 96:   */     }
/* 97:91 */     if (paramPsiElement2 == null) {
/* 98:91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "3", "org/intellij/plugins/relaxNG/compact/psi/impl/RncFileReferenceImpl", "processDeclarations" }));
/* 99:   */     }
/* :0:91 */     FollowFileHint localFollowFileHint = (FollowFileHint)paramPsiScopeProcessor.getHint(FollowFileHint.KEY);
/* :1:92 */     RncFile localRncFile = getReferencedFile();
/* :2:93 */     if ((localRncFile != null) && (localFollowFileHint != null) && (localFollowFileHint.doFollow(localRncFile))) {
/* :3:94 */       localRncFile.processDeclarations(paramPsiScopeProcessor, paramResolveState, paramPsiElement1, paramPsiElement2);
/* :4:   */     }
/* :5:96 */     return true;
/* :6:   */   }
/* :7:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.psi.impl.RncFileReferenceImpl

 * JD-Core Version:    0.7.0.1

 */